HTMLify
index.html
Views: 361 | Author: cody
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | <!DOCTYPE html> <html> <head> <meta charset='utf-8'> <meta http-equiv='X-UA-Compatible' content='IE=edge'> <title>Submit Button Animation</title> <meta name='viewport' content='width=device-width, initial-scale=1'> <link rel='stylesheet' type='text/css' media='screen' href='style.css'> </head> <body> <button class="btn" type="button"> <span class="btn__text">Submit</span> <svg class="btn__progress" viewBox="0 0 48 48" width="48px" height="48px"> <circle class="btn__progress-track" r="20" cx="24" cy="24" fill="none" stroke="#c7cad1" stroke-width="8" /> <circle class="btn__progress-fill" r="20" cx="24" cy="24" fill="none" stroke="#000000" stroke-width="8" transform="rotate(-90,24,24)" stroke-dasharray="125.66 125.66" stroke-dashoffset="125.66" /> <polyline class="btn__progress-check" points="12,24 20,32 36,16" fill="none" stroke="#fff" stroke-width="4" stroke-linecap="round" stroke-linejoin="round" stroke-dasharray="34 34" stroke-dashoffset="34" /> </svg> </button> <script> window.addEventListener("DOMContentLoaded", () => { const btn = document.querySelector("button"); var doneTimeout = null, resetTimeout = null; if (btn) { btn.addEventListener("click", function () { const runClass = "btn--running"; const doneClass = "btn--done"; const submitDuration = 2000; const resetDuration = 1500; // fake the submission this.disabled = true; this.classList.add(runClass); clearTimeout(doneTimeout); clearTimeout(resetTimeout); doneTimeout = setTimeout(() => { this.classList.remove(runClass); this.classList.add(doneClass); // reset the button resetTimeout = setTimeout(() => { this.disabled = false; this.classList.remove(doneClass); }, resetDuration); }, 600 + submitDuration); }); } }); </script> </body> </html> |